package com.etc.service.impl;

import java.util.List;

import com.etc.entity.AsGather;
import com.etc.entity.AsMatter;
import com.etc.mapper.AsGatherMapper;
import com.etc.mapper.AsMatterMapper;
import com.etc.service.IAsMatterService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 素材管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-11-27
 */
@Service
public class AsMatterServiceImpl implements IAsMatterService
{
    @Autowired
    private AsMatterMapper asMatterMapper;

    @Autowired
    private AsGatherMapper asGatherMapper;

    /**
     * 查询素材管理
     * 
     * @param id 素材管理主键
     * @return 素材管理
     */
    @Override
    public List selectAsMatterById(Long id)
    {
        return asMatterMapper.selectAsMatterById(id);
    }


    /**
     * 查询素材管理列表
     * 
     * @param
     * @return 素材管理
     */
    @Override
    public Page<AsMatter> selectAsMatterList(String keywords, int page , int limit)
    {
        PageHelper.startPage(page,limit);
        List<AsMatter> asMatters = asMatterMapper.selectAsMatterList("%" + keywords + "%");
        return (Page<AsMatter>) asMatters;
    }

    /**
     * 新增素材管理
     * 
     * @param asMatter 素材管理
     * @return 结果
     */
    @Override
    public AsMatter insertAsMatter(AsMatter asMatter,int boardid)
    {
        int i = asMatterMapper.insertAsMatter(asMatter);
        List<AsMatter> asMatters = asMatterMapper.selectAsMatterList(asMatter.getMattername());
        AsGather asGather = new AsGather();
        asGather.setBoardid(boardid);
        asGather.setMatterid(asMatters.get(0).getId());
        int i1 = asGatherMapper.insertAsGather(asGather);
        return asMatters.get(0);
    }

    /**
     * 修改素材管理
     * 
     * @param asMatter 素材管理
     * @return 结果
     */
    @Override
    public int updateAsMatter(AsMatter asMatter)
    {
        return asMatterMapper.updateAsMatter(asMatter);
    }

    /**
     * 批量删除素材管理
     * 
     * @param ids 需要删除的素材管理主键
     * @return 结果
     */
    @Override
    public int deleteAsMatterByIds(Long[] ids)
    {
        return asMatterMapper.deleteAsMatterByIds(ids);
    }

    /**
     * 删除素材管理信息
     * 
     * @param id 素材管理主键
     * @return 结果
     */
    @Override
    public int deleteAsMatterById(Long id)
    {
        return asMatterMapper.deleteAsMatterById(id);
    }
}
